/*
 * © Copyright 2011 Romain Marteau, Matthieu Totet
 * 
 *    This file is part of VineaToum.
 *
 *    VineaToum is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    VineaToum is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with VineaToum.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.vineatoum.view.stateView;

import java.awt.GridBagLayout;
import javax.swing.JLabel;

import org.vineatoum.business.Cuve;
import org.vineatoum.business.action.ActionDescriptor;
import org.vineatoum.business.action.analyse.AnalyseFermentation;
import org.vineatoum.business.action.analyse.AnalyseLabo;
import org.vineatoum.business.action.operationactive.Ensemmensage;
import org.vineatoum.business.action.operationactive.Pressurage;
import org.vineatoum.business.action.operationactive.Saignee;
import org.vineatoum.business.action.operationactive.Soutirage;
import org.vineatoum.business.action.operationpassive.ActionOnMarc;
import org.vineatoum.business.action.operationpassive.Oxygenation;
import org.vineatoum.business.enumeration.ETypeMarcAction;
import org.vineatoum.business.enumeration.ETypeOxygenation;
import org.vineatoum.business.state.Marc;
import org.vineatoum.controller.ActionController;
import org.vineatoum.controller.IActionController;
import org.vineatoum.model.abstraction.IVineaToumModel;
import org.vineatoum.observer.IObserverAction;
import org.vineatoum.view.action.ActionOnMarcPanel;
import org.vineatoum.view.action.AnalyseFermentationPanel;
import org.vineatoum.view.action.AnalyseLaboPanel;
import org.vineatoum.view.action.EnsemmensagePanel;
import org.vineatoum.view.action.OxygenationPanel;
import org.vineatoum.view.action.PressuragePanel;
import org.vineatoum.view.action.SaigneePanel;
import org.vineatoum.view.action.SoutiragePanel;
import org.vineatoum.view.component.JAccordion;
import org.vineatoum.view.component.OenologicalProductPanel;
import org.vineatoum.view.component.TrackingPanel;
import org.vineatoum.view.utils.JPanelWrapped;
import org.vineatoum.view.utils.jtablecustom.JTableCustom;

import java.awt.BorderLayout;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import java.awt.Insets;

import javax.swing.BoxLayout;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
import javax.swing.JButton;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.List;

public class MarcActionPanel extends JPanelWrapped implements IObserverAction {
	private static final long serialVersionUID = -5445564122111066285L;
	
	protected JLabel lblTitle;
	protected JLabel lblName;
	protected JLabel lblCuve;
	protected JLabel lblAnalyse;
	protected JLabel lblQte;
	protected JLabel lblVendanges;
	protected JLabel lblAnalyseLabo;
	
	protected JAccordion accordion;
	protected JPanel dataPanel;
	protected JPanel actionPanel;
	protected JTabbedPane tabPanel;
	protected TrackingPanel trackingPanel;
	
	protected JTableCustom<Soutirage> tableSoutirages;
	protected JTableCustom<Oxygenation> tableOxygenations;
	protected JTableCustom<ActionOnMarc> tableActionsOnMarc;
	protected JTableCustom<AnalyseFermentation> tableAnalysesFermentation;
	protected JTableCustom<AnalyseLabo> tableAnalysesLabo;
	
	protected JToolBar toolBarActions;
	
	protected JButton btnSaignee;
	protected JButton btnPressurer;
	protected JButton btnSoutirage;
	
	protected JButton btnPigeage;
	protected JButton btnRemontage;
	protected JButton btnDelestage;
	
	protected JButton btnChaptalisation;
	protected JButton btnLevurage;
	protected JButton btnAeration;
	protected JButton btnMicroOxy;
	protected JButton btnActivateur;
	
	protected JButton btnSuiviFermentation;
	protected JButton btnAnalyseLabo;
	
//	protected JButton btnSuiviFM;
	protected JButton btnAddChromato;
	protected JButton btnEnsemmensage;
	protected JButton btnKitMalo;
//	protected JButton btnAnalyseLaboFM;
	
	private IVineaToumModel model;
	private IActionController controller;

	/**
	 * Create the panel.
	 */
	public MarcActionPanel(final IVineaToumModel model, final Marc marc) {
		this.model = model;
		this.model.addObserver(this);

		this.controller = new ActionController(model);
		
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		
		dataPanel = new JPanel();
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
		gridBagLayout.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
		gridBagLayout.columnWeights = new double[] { 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0,
				1.0, Double.MIN_VALUE };
		gridBagLayout.rowWeights = new double[] { 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0 };
		dataPanel.setLayout(gridBagLayout);
		
		{
			lblTitle = new JLabel("Vue Marc");
			GridBagConstraints gbc_lblVueMout = new GridBagConstraints();
			gbc_lblVueMout.insets = new Insets(0, 0, 5, 5);
			gbc_lblVueMout.gridx = 2;
			gbc_lblVueMout.gridy = 0;
			dataPanel.add(lblTitle, gbc_lblVueMout);
		}
		{
			lblName = new JLabel("Nom : " + marc.getName());
			GridBagConstraints gbc_lblVueMout = new GridBagConstraints();
			gbc_lblVueMout.insets = new Insets(0, 0, 5, 5);
			gbc_lblVueMout.gridx = 2;
			gbc_lblVueMout.gridy = 1;
			dataPanel.add(lblName, gbc_lblVueMout);
		}
		{
			lblCuve = new JLabel("Cuve: " + marc.getCuve());
			GridBagConstraints gbc_lblVueMout = new GridBagConstraints();
			gbc_lblVueMout.insets = new Insets(0, 0, 5, 5);
			gbc_lblVueMout.gridx = 2;
			gbc_lblVueMout.gridy = 2;
			dataPanel.add(lblCuve, gbc_lblVueMout);
		}
		{
			lblQte = new JLabel("Quantité: " + marc.getQuantity());
			GridBagConstraints gbc_lblVueMout = new GridBagConstraints();
			gbc_lblVueMout.insets = new Insets(0, 0, 5, 5);
			gbc_lblVueMout.gridx = 4;
			gbc_lblVueMout.gridy = 2;
			dataPanel.add(lblQte, gbc_lblVueMout);
		}
		{
			lblAnalyse = new JLabel("Derniére analyse - Densité : Récupérer la densité (date) - Acidité : Récupérer l'acidité (date)");// + mout.getQuantity());
			GridBagConstraints gbc_lblVueMout = new GridBagConstraints();
			gbc_lblVueMout.insets = new Insets(0, 0, 5, 5);
			gbc_lblVueMout.gridx = 2;
			gbc_lblVueMout.gridy = 3;
			dataPanel.add(lblAnalyse, gbc_lblVueMout);
		}
		{
			lblAnalyseLabo = new JLabel("Date du dernier échantillon laboratoire : + récupérer date. Sinon cacher");// + mout.getQuantity());
			GridBagConstraints gbc_lblVueMout = new GridBagConstraints();
			gbc_lblVueMout.insets = new Insets(0, 0, 5, 5);
			gbc_lblVueMout.gridx = 2;
			gbc_lblVueMout.gridy = 4;
			dataPanel.add(lblAnalyseLabo, gbc_lblVueMout);
		}
		{
			lblVendanges = new JLabel("Origine: Récupérer la liste des antécédents de type plantation");// + mout.getQuantity());
			GridBagConstraints gbc_lblVueMout = new GridBagConstraints();
			gbc_lblVueMout.insets = new Insets(0, 0, 5, 5);
			gbc_lblVueMout.gridx = 4;
			gbc_lblVueMout.gridy = 4;
			dataPanel.add(lblVendanges, gbc_lblVueMout);
		}
		
		add(dataPanel);

		accordion = new JAccordion();
		
		actionPanel = new JPanel(new GridLayout(0, 1));
		
		tabPanel = new JTabbedPane();
		actionPanel.add(tabPanel);
		
		{			
			tableSoutirages = new JTableCustom<Soutirage>(new Soutirage()) {
				private static final long serialVersionUID = 1L;

				protected boolean fireEditingStarted(final JTableCustom<Soutirage> table,
						final int row, int column) {
					table.getCellEditor().stopCellEditing();
					
					final SoutiragePanel soutiragePanel = new SoutiragePanel(model,
							(Soutirage) table.getValueAt(row));
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), soutiragePanel,
							"Ajouter", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
							null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						table.setValueAt(soutiragePanel.getDate(), row, 0);
						table.setValueAt(soutiragePanel.getLieQte(), row, 1);
						table.setValueAt(soutiragePanel.getCuveDestination(), row, 2);
						table.setValueAt(soutiragePanel.getCuveLie(), row, 3);
					}

					return false;
				}
			};

			// FIXME
			List<Soutirage> soutirages = new ArrayList<Soutirage>();
//			for (Iterator iterator = mout.getAnalyses().iterator(); iterator.hasNext();) {
//				Analyse analyse = (Analyse) iterator.next();
//				prelevements.add((Prelevement) analyse);
//
//			}
			tableSoutirages.setData(soutirages);
			
			JPanel panel = new JPanel(new BorderLayout());
			panel.add(tableSoutirages, BorderLayout.CENTER);
			panel.add(tableSoutirages.getTableHeader(), BorderLayout.NORTH);
			
			tabPanel.addTab("Soutirages", panel);
		}
		{			
			tableOxygenations = new JTableCustom<Oxygenation>(new Oxygenation()) {
				private static final long serialVersionUID = 1L;

				protected boolean fireEditingStarted(final JTableCustom<Oxygenation> table, final int row, int column) {
					table.getCellEditor().stopCellEditing();
					
					final OxygenationPanel oxygenationPanel = new OxygenationPanel(model, (Oxygenation) table.getValueAt(row));
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), oxygenationPanel,
							"Ajouter", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
							null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						table.setValueAt(oxygenationPanel.getDate(), row, 0);
						table.setValueAt(oxygenationPanel.getDuree(), row, 1);
						table.setValueAt(oxygenationPanel.getType(), row, 2);
					}

					return false;
				}
			};

			// FIXME
			List<Oxygenation> oxygenations = new ArrayList<Oxygenation>();
//			for (Iterator iterator = mout.getAnalyses().iterator(); iterator.hasNext();) {
//				Analyse analyse = (Analyse) iterator.next();
//				prelevements.add((Prelevement) analyse);
//
//			}
			tableOxygenations.setData(oxygenations);
			
			JPanel panel = new JPanel(new BorderLayout());
			panel.add(tableOxygenations, BorderLayout.CENTER);
			panel.add(tableOxygenations.getTableHeader(), BorderLayout.NORTH);
			
			tabPanel.addTab("Oxygenations", panel);
		}
		{			
			tableAnalysesFermentation = new JTableCustom<AnalyseFermentation>(new AnalyseFermentation()) {
				private static final long serialVersionUID = 1L;

				protected boolean fireEditingStarted(final JTableCustom<AnalyseFermentation> table,
						final int row, int column) {
					table.getCellEditor().stopCellEditing();
					
					final AnalyseFermentationPanel analyseFAPanel = new AnalyseFermentationPanel(model, (AnalyseFermentation) table.getValueAt(row));
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), analyseFAPanel,
							"Ajouter", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
							null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						table.setValueAt(analyseFAPanel.getDate(), row, 0);
						table.setValueAt(analyseFAPanel.getDensity(), row, 1);
						table.setValueAt(analyseFAPanel.getTemperature(), row, 2);
						table.setValueAt(analyseFAPanel.getComment(), row, 3);
					}

					return false;
				}
			};

			// FIXME
			List<AnalyseFermentation> analysesFA = new ArrayList<AnalyseFermentation>();
//			for (Iterator iterator = mout.getAnalyses().iterator(); iterator.hasNext();) {
//				Analyse analyse = (Analyse) iterator.next();
//				prelevements.add((Prelevement) analyse);
//
//			}
			tableAnalysesFermentation.setData(analysesFA);
			
			JPanel panel = new JPanel(new BorderLayout());
			panel.add(tableAnalysesFermentation, BorderLayout.CENTER);
			panel.add(tableAnalysesFermentation.getTableHeader(), BorderLayout.NORTH);
			
			tabPanel.addTab("Suivi Fermentation", panel);
		}
		{			
			tableAnalysesLabo = new JTableCustom<AnalyseLabo>(new AnalyseLabo()) {
				private static final long serialVersionUID = 1L;

				protected boolean fireEditingStarted(final JTableCustom<AnalyseLabo> table,	final int row, int column) {
					table.getCellEditor().stopCellEditing();
					
					final AnalyseLaboPanel analyseLaboPanel = new AnalyseLaboPanel(model, (AnalyseLabo) table.getValueAt(row));
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), analyseLaboPanel,
							"Ajouter", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
							null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						table.setValueAt(analyseLaboPanel.getAnalyseLabo(), row);
					}

					return false;
				}
			};

			// FIXME
			List<AnalyseLabo> analyses = new ArrayList<AnalyseLabo>();
//			for (Iterator iterator = mout.getAnalyses().iterator(); iterator.hasNext();) {
//				Analyse analyse = (Analyse) iterator.next();
//				prelevements.add((Prelevement) analyse);
//
//			}
			tableAnalysesLabo.setData(analyses);
			
			JPanel panel = new JPanel(new BorderLayout());
			panel.add(tableAnalysesLabo, BorderLayout.CENTER);
			panel.add(tableAnalysesLabo.getTableHeader(), BorderLayout.NORTH);
			
			tabPanel.addTab("Analyses Labo", panel);
		}
		{			
			tableActionsOnMarc = new JTableCustom<ActionOnMarc>(new ActionOnMarc()) {
				private static final long serialVersionUID = 1L;

				protected boolean fireEditingStarted(final JTableCustom<ActionOnMarc> table, final int row, int column) {
					table.getCellEditor().stopCellEditing();
					
					final ActionOnMarcPanel actionOnMarcPanel = new ActionOnMarcPanel(model, (ActionOnMarc) table.getValueAt(row));
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), actionOnMarcPanel,
							"Ajouter", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
							null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						table.setValueAt(actionOnMarcPanel.getDate(), row, 0);
						table.setValueAt(actionOnMarcPanel.getDuree(), row, 1);
						table.setValueAt(actionOnMarcPanel.getType(), row, 2);
					}

					return false;
				}
			};

			// FIXME
			List<ActionOnMarc> actions = new ArrayList<ActionOnMarc>();
//			for (Iterator iterator = mout.getAnalyses().iterator(); iterator.hasNext();) {
//				Analyse analyse = (Analyse) iterator.next();
//				prelevements.add((Prelevement) analyse);
//
//			}
			tableActionsOnMarc.setData(actions);
			
			JPanel panel = new JPanel(new BorderLayout());
			panel.add(tableActionsOnMarc, BorderLayout.CENTER);
			panel.add(tableActionsOnMarc.getTableHeader(), BorderLayout.NORTH);
			
			tabPanel.addTab("Actions sur Marc", panel);
		}
		{
			btnSoutirage = new JButton("Faire un soutirage");
			btnSoutirage.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					final SoutiragePanel soutiragePanel = new SoutiragePanel(model, new Soutirage());
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), soutiragePanel,
							"Soutirage", JOptionPane.OK_CANCEL_OPTION,
							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						Soutirage soutirage = new Soutirage();
						try {
							soutirage.setDate(soutiragePanel.getDate());
							soutirage.setLieQte((Float) soutiragePanel.getLieQte());
							soutirage.setCuveDestination((Cuve) soutiragePanel.getCuveDestination());
							soutirage.setCuveLie((Cuve) soutiragePanel.getCuveLie());
						} catch (ClassCastException e) {
							// TODO: handle exception
							System.err.println("ERRor");
							e.printStackTrace();
						}
						tableSoutirages.addRow(soutirage);
						ActionDescriptor action = new ActionDescriptor(soutirage);
						//TODO action.addVinInput(plantation, 100);

						controller.addAction(action);

					}

				}
			});
		}
		{
			btnSaignee = new JButton("Faire une saignée");
			btnSaignee.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					final SaigneePanel saigneePanel = new SaigneePanel(model, new Saignee());
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), saigneePanel,
							"Saignée", JOptionPane.OK_CANCEL_OPTION,
							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						//TODO
					}

				}
			});
		}
		{
			btnPressurer = new JButton("Pressurer");
			btnPressurer.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) { //TODO
					final PressuragePanel pressurerActionPanel = new PressuragePanel(model, new Pressurage());
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), pressurerActionPanel,
							"Pressurer", JOptionPane.OK_CANCEL_OPTION,
							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						try {
	
						} catch (ClassCastException e) {
							// TODO: handle exception
							e.printStackTrace();
						}
					}
	
				}
			});
		}
		{
			btnSuiviFermentation = new JButton("Suivi de FA");
			btnSuiviFermentation.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					final AnalyseFermentationPanel analysePanel = new AnalyseFermentationPanel (model, new AnalyseFermentation());
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), analysePanel,
							"Soutirage", JOptionPane.OK_CANCEL_OPTION,
							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						AnalyseFermentation analyse = new AnalyseFermentation();
						try {
							analyse.setDate(analysePanel.getDate());
							analyse.setDensity(analysePanel.getDensity());
							analyse.setTemperature(analysePanel.getTemperature());
							analyse.setComment(analysePanel.getComment());
						} catch (ClassCastException e) {
							// TODO: handle exception
							System.err.println("ERRor");
							e.printStackTrace();
						}
						tableAnalysesFermentation.addRow(analyse);
						ActionDescriptor action = new ActionDescriptor(analyse);
						//TODO action.addVinInput(plantation, 100);

						controller.addAction(action);

					}

				}
			});
		}
		{
			btnChaptalisation = new JButton("Chaptalisation");
			btnChaptalisation.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					final OenologicalProductPanel oenoPanel = new OenologicalProductPanel(); //TODO
					oenoPanel.setFilter("Sucre");
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), oenoPanel,
							"Chaptalisation", JOptionPane.OK_CANCEL_OPTION,
							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						
					}

				}
			}); //TODO
		}
		{
			btnLevurage = new JButton("Levurage");
			btnLevurage.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					final OenologicalProductPanel oenoPanel = new OenologicalProductPanel(); //TODO
					oenoPanel.setFilter("Levure");
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), oenoPanel,
							"Levurage", JOptionPane.OK_CANCEL_OPTION,
							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						
					}

				}
			}); //TODO
		}
		{
			btnDelestage = new JButton("Delestage");
			btnDelestage.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {					
					final ActionOnMarcPanel actionMarcPanel = new ActionOnMarcPanel(model, new ActionOnMarc());
					actionMarcPanel.setType(ETypeMarcAction.DELESTAGE);
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), actionMarcPanel,
							"Délestage", JOptionPane.OK_CANCEL_OPTION,
							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						ActionOnMarc actionOnMarc = new ActionOnMarc();
						
						try {
							actionOnMarc.setDate(actionMarcPanel.getDate());
							actionOnMarc.setDuree(actionMarcPanel.getDuree());
							actionOnMarc.setType(actionMarcPanel.getType());
						} catch (ClassCastException e) {
							// TODO: handle exception
							System.err.println("ERRor");
							e.printStackTrace();
						}
						tableActionsOnMarc.addRow(actionOnMarc);
						ActionDescriptor action = new ActionDescriptor(actionOnMarc);
						//TODO action.addVinInput(plantation, 100);

						controller.addAction(action);

					}

				}
			}); //TODO
		}
		{
			btnPigeage = new JButton("Pigeage");
			btnPigeage.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {					
					final ActionOnMarcPanel actionMarcPanel = new ActionOnMarcPanel(model, new ActionOnMarc());
					actionMarcPanel.setType(ETypeMarcAction.PIGEAGE);
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), actionMarcPanel,
							"Délestage", JOptionPane.OK_CANCEL_OPTION,
							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						ActionOnMarc actionOnMarc = new ActionOnMarc();
						
						try {
							actionOnMarc.setDate(actionMarcPanel.getDate());
							actionOnMarc.setDuree(actionMarcPanel.getDuree());
							actionOnMarc.setType(actionMarcPanel.getType());
						} catch (ClassCastException e) {
							// TODO: handle exception
							System.err.println("ERRor");
							e.printStackTrace();
						}
						tableActionsOnMarc.addRow(actionOnMarc);
						ActionDescriptor action = new ActionDescriptor(actionOnMarc);
						//TODO action.addVinInput(plantation, 100);

						controller.addAction(action);

					}

				}
			});//TODO
		}
		{
			btnRemontage = new JButton("Remontage");
			btnRemontage.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {					
					final ActionOnMarcPanel actionMarcPanel = new ActionOnMarcPanel(model, new ActionOnMarc());
					actionMarcPanel.setType(ETypeMarcAction.REMONTAGE);
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), actionMarcPanel,
							"Délestage", JOptionPane.OK_CANCEL_OPTION,
							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						ActionOnMarc actionOnMarc = new ActionOnMarc();
						
						try {
							actionOnMarc.setDate(actionMarcPanel.getDate());
							actionOnMarc.setDuree(actionMarcPanel.getDuree());
							actionOnMarc.setType(actionMarcPanel.getType());
						} catch (ClassCastException e) {
							// TODO: handle exception
							System.err.println("ERRor");
							e.printStackTrace();
						}
						tableActionsOnMarc.addRow(actionOnMarc);
						ActionDescriptor action = new ActionDescriptor(actionOnMarc);
						//TODO action.addVinInput(plantation, 100);

						controller.addAction(action);

					}

				}
			}); //TODO
		}
		{
			btnAeration = new JButton("Aeration");
			btnAeration.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					final OxygenationPanel oxygenationPanel = new OxygenationPanel(model, new Oxygenation());
					oxygenationPanel.setType(ETypeOxygenation.AERATION);
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), oxygenationPanel,
							"Aération", JOptionPane.OK_CANCEL_OPTION,
							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						Oxygenation aeration = new Oxygenation();
						
						try {
							aeration.setDate(oxygenationPanel.getDate());
							aeration.setDuree(oxygenationPanel.getDuree());
							aeration.setType(oxygenationPanel.getType());
						} catch (ClassCastException e) {
							// TODO: handle exception
							System.err.println("ERRor");
							e.printStackTrace();
						}
						tableOxygenations.addRow(aeration);
						ActionDescriptor action = new ActionDescriptor(aeration);
						//TODO action.addVinInput(plantation, 100);

						controller.addAction(action);

					}
				}
			});	
		}
		{
			btnMicroOxy = new JButton("Micro Oxygénation");
			btnMicroOxy.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					final OxygenationPanel oxygenationPanel = new OxygenationPanel(model, new Oxygenation());
					oxygenationPanel.setType(ETypeOxygenation.MICROOXYGENATION);
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), oxygenationPanel,
							"Micro Oxygénation", JOptionPane.OK_CANCEL_OPTION,
							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						Oxygenation microOxygenation = new Oxygenation();
						
						try {
							microOxygenation.setDate(oxygenationPanel.getDate());
							microOxygenation.setDuree(oxygenationPanel.getDuree());
							microOxygenation.setType(oxygenationPanel.getType());
						} catch (ClassCastException e) {
							// TODO: handle exception
							System.err.println("ERRor");
							e.printStackTrace();
						}
						tableOxygenations.addRow(microOxygenation);
						ActionDescriptor action = new ActionDescriptor(microOxygenation);
						//TODO action.addVinInput(plantation, 100);

						controller.addAction(action);

					}
				}
			});
		}
		{
			btnActivateur = new JButton("Activateur de fermentation");
			btnActivateur.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					final OenologicalProductPanel oenoPanel = new OenologicalProductPanel(); //TODO
					oenoPanel.setFilter("Activateur");
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), oenoPanel,
							"Activateur de fermentation", JOptionPane.OK_CANCEL_OPTION,
							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						
					}

				} //TODO
			});
		}
		{
			btnAnalyseLabo = new JButton("Analyse Labo");
			btnAnalyseLabo.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					final AnalyseLaboPanel analyseLaboPanel = new AnalyseLaboPanel(model, new AnalyseLabo());
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), analyseLaboPanel,
							"Analyse Labo", JOptionPane.OK_CANCEL_OPTION,
							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						AnalyseLabo analyseLabo = analyseLaboPanel.getAnalyseLabo();
						tableAnalysesLabo.addRow(analyseLabo);
						ActionDescriptor action = new ActionDescriptor(analyseLabo);
						//TODO action.addVinInput(plantation, 100);

						controller.addAction(action);
					}

				}
			});
		}
//		{
//			btnSuiviFM = new JButton("Suivi FM");
//			btnSuiviFM.addActionListener(new ActionListener() {
//				public void actionPerformed(ActionEvent arg0) {
//					final SoutiragePanel soutiragePanel = new SoutiragePanel(model, new Soutirage());
//					Object[] options = { "OK", "Annuler" };
//					int n = JOptionPane.showOptionDialog(getRootPane(), soutiragePanel,
//							"Soutirage", JOptionPane.OK_CANCEL_OPTION,
//							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
//					if (n == JOptionPane.OK_OPTION) {
//						
//					}
//
//				}TODO
//			});
//		}
		{
			btnAddChromato = new JButton("Ajouter une chromato");
//			btnAddChromato.addActionListener(new ActionListener() {
//				public void actionPerformed(ActionEvent arg0) {
//					final SoutiragePanel soutiragePanel = new SoutiragePanel(model, new Soutirage());
//					Object[] options = { "OK", "Annuler" };
//					int n = JOptionPane.showOptionDialog(getRootPane(), soutiragePanel,
//							"Soutirage", JOptionPane.OK_CANCEL_OPTION,
//							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
//					if (n == JOptionPane.OK_OPTION) {
//						
//					}
//
//				}TODO
//			});
		}
		{
			btnEnsemmensage = new JButton("Ensemmensage");
			btnEnsemmensage.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					final EnsemmensagePanel ensemmensagePanel = new EnsemmensagePanel(model, new Ensemmensage());
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), ensemmensagePanel,
							"Ensemmensage", JOptionPane.OK_CANCEL_OPTION,
							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						Ensemmensage ensemmensage = new Ensemmensage();
						ensemmensage.setDate(ensemmensagePanel.getDate());
						ensemmensage.setLieQte(ensemmensagePanel.getLieQte());
						ensemmensage.setCuveLie(ensemmensagePanel.getCuveLie());
						
						ActionDescriptor action = new ActionDescriptor(ensemmensage);
						//TODO action.addVinInput(plantation, 100);

						controller.addAction(action);
					}

				}
			});
		}
		{
			btnKitMalo = new JButton("Kit Malo");
			btnKitMalo.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					final OenologicalProductPanel oenoPanel = new OenologicalProductPanel(); //TODO
					oenoPanel.setFilter("kitmalo");
					Object[] options = { "OK", "Annuler" };
					int n = JOptionPane.showOptionDialog(getRootPane(), oenoPanel,
							"Kit Malo", JOptionPane.OK_CANCEL_OPTION,
							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
					if (n == JOptionPane.OK_OPTION) {
						
					}

				}
			}); //TODO
		}
//		{
//			btnAnalyseLaboFM = new JButton("Analyse Labo FM");
//			btnAnalyseLaboFM.addActionListener(new ActionListener() {
//				public void actionPerformed(ActionEvent arg0) {
//					final SoutiragePanel soutiragePanel = new SoutiragePanel(model, new Soutirage());
//					Object[] options = { "OK", "Annuler" };
//					int n = JOptionPane.showOptionDialog(getRootPane(), soutiragePanel,
//							"Soutirage", JOptionPane.OK_CANCEL_OPTION,
//							JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
//					if (n == JOptionPane.OK_OPTION) {
//						
//					}
//TODO
//				}
//			});
//		}
		{
			toolBarActions = new JToolBar();
			toolBarActions.setOrientation(SwingConstants.VERTICAL);
			toolBarActions.add(btnSoutirage);
			toolBarActions.add(new JSeparator(SwingConstants.HORIZONTAL));
			toolBarActions.add(btnPressurer);
			toolBarActions.add(btnSaignee);
			toolBarActions.add(new JSeparator(SwingConstants.HORIZONTAL));
			toolBarActions.add(btnChaptalisation);
			toolBarActions.add(btnLevurage);
			toolBarActions.add(new JSeparator(SwingConstants.HORIZONTAL));
			toolBarActions.add(btnPigeage);
			toolBarActions.add(btnDelestage);
			toolBarActions.add(btnRemontage);
			toolBarActions.add(new JSeparator(SwingConstants.HORIZONTAL));
			toolBarActions.add(btnSuiviFermentation);
			toolBarActions.add(btnAnalyseLabo);
			toolBarActions.add(new JSeparator(SwingConstants.HORIZONTAL));
			toolBarActions.add(btnAeration);
			toolBarActions.add(btnMicroOxy);
			toolBarActions.add(new JSeparator(SwingConstants.HORIZONTAL));
//			toolBarActions.add(btnSuiviFM);
			toolBarActions.add(btnActivateur);
			toolBarActions.add(btnEnsemmensage);
			toolBarActions.add(new JSeparator(SwingConstants.HORIZONTAL));
			toolBarActions.add(btnKitMalo);
			toolBarActions.add(btnAddChromato);
//			toolBarActions.add(btnAnalyseLaboFM);
//			
//			final JPopupMenu jPopupMenu = new JPopupMenu();
//			jPopupMenu.add(new JMenuItem("1"));
//			jPopupMenu.add(new JMenuItem("2"));
//			btnAnalyseLaboFM.addActionListener(new ActionListener() {
//
//			    public void actionPerformed(ActionEvent e) {
//			    	jPopupMenu.show(btnAnalyseLaboFM,  0, btnAnalyseLaboFM.getHeight());
//			    }
//			});
		}
		{
			actionPanel = new JPanel(new BorderLayout());
			
			actionPanel.add(tabPanel, BorderLayout.CENTER);
			actionPanel.add(toolBarActions, BorderLayout.WEST);
		}
		{
			trackingPanel = new TrackingPanel(marc);

			accordion.addBar("Action", actionPanel);
			accordion.addBar("Historique", trackingPanel);
//			GridBagConstraints gbc_panel_1 = new GridBagConstraints();
//			gbc_panel_1.gridheight = 5;
//			gbc_panel_1.insets = new Insets(0, 0, 5, 5);
//			gbc_panel_1.fill = GridBagConstraints.BOTH;
//			gbc_panel_1.gridx = 2;
//			gbc_panel_1.gridy = 16;
//			add(panel_1, gbc_panel_1);
			
			add(accordion, BorderLayout.CENTER);
		}
	}

	@Override
	public void doWhenWrapperCancelClick() {
		// TODO Auto-generated method stub

	}

	@Override
	public void doWhenWrapperOkClick() {
		// TODO Auto-generated method stub

	}
	
	

}
